package com.chanyachting.emall.domain;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.chanyachting.emall.dao.MemberopertionmenuDAO;
import com.chanyachting.emall.domain.base.BaseMemberopertionmenu;

/**
 * This is the object class that relates to the memberopertionmenu table.
 * Any customizations belong here.
 */
public class Memberopertionmenu extends BaseMemberopertionmenu {

/*[CONSTRUCTOR MARKER BEGIN]*/
	public Memberopertionmenu () {
		super();
	}

	/**
	 * Constructor for primary key
	 */
	public Memberopertionmenu (java.lang.Integer _id) {
		super(_id);
		
		Memberopertionmenu mom=(Memberopertionmenu)new MemberopertionmenuDAO().load(Memberopertionmenu.class, _id);
		
		if(mom!=null){
			
			try {
				BeanUtils.copyProperties(this, mom);
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/**
	 * Constructor for required fields
	 */
	public Memberopertionmenu (
		java.lang.Integer _id,
		java.lang.Integer _memberId,
		java.lang.Integer _menuGroupId) {

		super (
			_id,
			_memberId,
			_menuGroupId);
	}
/*[CONSTRUCTOR MARKER END]*/
	
	public static void deleteByMemberId(int memberId){
		
//		String args[]={String.valueOf(memberId)};
//		
//		new MemberopertionmenuDAO().executeBySQL("delete from memberopertionmenu where memberId=? ", args);
		
		List list=listByMemberId(memberId);
		
		if(list!=null && list.size()>0){
			
			for(int i=0;i<list.size();i++){
				
				Memberopertionmenu mm=(Memberopertionmenu)list.get(i);
				
				mm.delete();
				
			}
			
		}
		
	}
	
	
	public static List<Memberopertionmenu> list(){
		
		
		return new MemberopertionmenuDAO().find("from Memberopertionmenu");
	}
	
	
	public static List<Memberopertionmenu> listByMemberId(int memberId){
		
		String args[]={String.valueOf(memberId)};
		
		return new MemberopertionmenuDAO().find("from Memberopertionmenu where memberId=?",args);
	}
	
	
	public boolean save(){
		
		new MemberopertionmenuDAO().save(this);
		
		return true;
	}
	
	
	public boolean delete(){
		
		new MemberopertionmenuDAO().delete(this);
		
		return true;
	}
	
	public boolean update(){
		
		new MemberopertionmenuDAO().update(this);
		
		return true;
	}
	
}